<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script>
    window.onload=function (){
      let oBtn=document.getElementById('btn1');

      oBtn.onclick=function (){
        //不兼容IE6
        let xhr=new XMLHttpRequest();

        /*if(window.XMLHttpRequest){
          var xhr=new XMLHttpRequest();       //ajax、xhr
        }else{
          var xhr=new ActiveXObject('Microsoft.XMLHttp');
        }*/

        //连接
        //true-异步
        //false-同步
        xhr.open('GET', '1.php?a=12&b=5', true);

        //发送
        xhr.send();

        //接收
        xhr.onreadystatechange=function (){
          //4——完事
          if(xhr.readyState==4){
            //成功——2xx、304
            if(xhr.status>=200 && xhr.status<300 || xhr.status==304){
              alert('成功'+xhr.responseText);
            }else{
              alert('失败');
            }
          }
        };
      };
    };
    </script>
  </head>
  <body>
    <input type="button" value="按钮" id="btn1">
  </body>
</html>
